import wx.grid
import pandas as pd


class DataFrameGrid(wx.grid.GridTableBase):
    # model类型
    def __init__(self, df=pd.DataFrame()):
        wx.grid.GridTableBase.__init__(self)
        self.data = df.values
        self.columns = df.columns.values
        self.row_index = df.index.values

    def GetValue(self, row, col):
        print('get value: ', (row, col))
        return self.data[row][col]

    def SetValue(self, row, col, value):
        print('set value: ', (row, col, value))

    def GetRowLabelValue(self, row):
        print('get row label:')
        return str(self.columns[row])

    def GetColLabelValue(self, col):
        print('get col label: ', str(self.row_index[col]))
        return str(self.row_index[col])

    def GetNumberRows(self):
        print('get number rows: ', len(self.data))
        return len(self.data)

    def GetNumberCols(self):
        print('get number columns: ', len(self.columns))
        return len(self.columns)

    NumberCols = property(lambda self: self.GetNumberCols, lambda self, v: None, lambda self: None)

    NumberRows = property(lambda self: self.GetNumberRows, lambda self, v: None, lambda self: None)
